﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Map
{
    public class FileOperation
    {
        private string path;
        public FileOperation(string _path)
        {
            path = _path;
        }


        //分割提取字符串中的英文、中文单词
        public List<string> readStrToList(string str)
        {
            List<string> list = new List<string>();
            Regex cnReg = new Regex("[\u4e00-\u9fa5]+"); //分割提取字符串中的中文词语
            Regex enReg = new Regex("[a-zA-Z0-9]+");//分割提取字符串中的英文单词
            foreach (Match item in enReg.Matches(str))
                list.Add(item.ToString());

            return list;
        }



        //一行一行读取TXT数据并返回List
        public List<string> ReadList()
        {
            List<string> result = new List<string>();
            string s = "";
            using (StreamReader sr = new StreamReader(path, Encoding.Default))
            {
                // sr.ReadLine()   读取文本每行的内容，然后复制给 s,如果s不为null ,就循环
                while ((s = sr.ReadLine()) != null)
                    result.Add(s);
            }
            return result;
        }



        public List<string> readFile()
        {
            List<string> result = new List<string>();
            Regex enReg = new Regex("[a-zA-Z0-9]+");//分割提取字符串中的英文单词
            string s = "";
            using (StreamReader sr = new StreamReader(path, Encoding.Default))
            {
                while ((s = sr.ReadLine()) != null)
                {
                    foreach (Match item in enReg.Matches(s))
                        result.Add(item.ToString());
                }                
            }
            return result;
        }


    }
}
